import { ArrowLeftOutlined, ArrowRightOutlined, SaveOutlined, RollbackOutlined, EyeOutlined, FileTextOutlined, TeamOutlined, SafetyCertificateOutlined } from '@/utils/icons';
import React, { useState, useEffect } from 'react';
import { Card, Steps, Button, Space, message, Row, Col, Descriptions } from 'antd';

import ProjectBasicInfo from '../../../components/project/ProjectBasicInfo';
import ProjectMembers from '../../../components/project/ProjectMembers';
import ProjectRisks from '../../../components/project/ProjectRisks';
import ContractStep from './ContractStep';
import AcceptanceStep from './AcceptanceStep';

const { Step } = Steps;

export default function ProjectEditFormRefactored({ projectId, projectCode, subProjectName, onBack }) {
  const [currentStep, setCurrentStep] = useState(0);
  const [projectData, setProjectData] = useState({});
  const [members, setMembers] = useState([]);
  const [risks, setRisks] = useState([]);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    fetchProjectData();
  }, [projectId]);

  const fetchProjectData = async () => {
    setLoading(true);
    try {
      // 模拟API调用
      const mockData = {
        projectName: '示例项目',
        projectCode: projectCode || 'PRJ001',
        customer: '阿里巴巴集团',
        company: '凯泽利科技股份有限公司',
        startDate: '2024-01-01',
        endDate: '2024-12-31',
        budget: 1000000,
        projectManager: '张三',
        description: '这是一个示例项目描述'
      };
      setProjectData(mockData);
    } catch (error) {
      message.error('获取项目数据失败');
    } finally {
      setLoading(false);
    }
  };

  const steps = [
    {
      title: '基本信息',
      icon: <FileTextOutlined />,
      content: <ProjectBasicInfo projectData={projectData} />
    },
    {
      title: '项目成员',
      icon: <TeamOutlined />,
      content: <ProjectMembers members={members} onMembersChange={setMembers} />
    },
    {
      title: '风险管控',
      icon: <SafetyCertificateOutlined />,
      content: <ProjectRisks risks={risks} onRisksChange={setRisks} />
    },
    {
      title: '合同信息',
      icon: <FileTextOutlined />,
      content: <ContractStep />
    },
    {
      title: '验收标准',
      icon: <SafetyCertificateOutlined />,
      content: <AcceptanceStep />
    }
  ];

  const handleNext = () => {
    if (currentStep < steps.length - 1) {
      setCurrentStep(currentStep + 1);
    }
  };

  const handlePrev = () => {
    if (currentStep > 0) {
      setCurrentStep(currentStep - 1);
    }
  };

  const handleSave = () => {
    message.success('保存成功');
  };

  const handleSubmit = () => {
    message.success('提交成功');
    if (onBack) {
      onBack();
    }
  };

  return (
    <div style={{ padding: 24 }}>
      <Card>
        <div style={{ marginBottom: 24 }}>
          <Space>
            <Button icon={<ArrowLeftOutlined />} onClick={onBack}>
              返回
            </Button>
            <Button icon={<EyeOutlined />}>
              预览
            </Button>
            <Button icon={<SaveOutlined />} onClick={handleSave}>
              保存
            </Button>
            <Button type="primary" onClick={handleSubmit}>
              提交
            </Button>
          </Space>
        </div>

        <Descriptions title="项目信息" bordered column={2} style={{ marginBottom: 24 }}>
          <Descriptions.Item label="项目名称">{projectName}</Descriptions.Item>
          <Descriptions.Item label="子项目名称">{subProjectName}</Descriptions.Item>
          <Descriptions.Item label="项目状态">进行中</Descriptions.Item>
          <Descriptions.Item label="创建时间">2024-01-01</Descriptions.Item>
        </Descriptions>

        <Steps current={currentStep} style={{ marginBottom: 24 }}>
          {steps.map((step, index) => (
            <Step key={index} title={step.title} icon={step.icon} />
          ))}
        </Steps>

        <Card>
          {steps[currentStep].content}
        </Card>

        <div style={{ marginTop: 24, textAlign: 'right' }}>
          <Space>
            {currentStep > 0 && (
              <Button onClick={handlePrev}>
                <ArrowLeftOutlined />
                上一步
              </Button>
            )}
            {currentStep < steps.length - 1 && (
              <Button type="primary" onClick={handleNext}>
                下一步
                <ArrowRightOutlined />
              </Button>
            )}
            {currentStep === steps.length - 1 && (
              <Button type="primary" onClick={handleSubmit}>
                完成
              </Button>
            )}
          </Space>
        </div>
      </Card>
    </div>
  );
}
